package com.itheima.motorcycletype.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.motorcycletype.dao.MotorcycleTypeMapper;
import com.itheima.motorcycletype.pojo.MotorcycleType;
import com.itheima.motorcycletype.service.MotorcycleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class MotorcycleTypeServiceImpl implements MotorcycleTypeService {
    @Autowired
    private MotorcycleTypeMapper motorcycleTypeMapper;

    /**
     * 分页查询
     * @param map
     * @return
     */
    @Override
    public Page<MotorcycleType> selectAll(Map<String,Object> map) {
        Integer page=1;
        Integer size=10;
        if (map.get("page")!=null&&!"".equals(map.get("page"))){
            page= Integer.parseInt((String)map.get("page")) ;
        }
        if (map.get("size")!=null&&!"".equals(map.get("size"))){
            size= Integer.parseInt((String)map.get("size")) ;
        }
        PageHelper.startPage(page,size);
        return (Page<MotorcycleType>) motorcycleTypeMapper.selectAll();
    }


    /**
     * 添加
     * @param motorcycleType
     * @return
     */
    @Override
    public Integer add(MotorcycleType motorcycleType) {
        return motorcycleTypeMapper.insert(motorcycleType);
    }

    /**
     * 修改
     * @param motorcycleType
     * @return
     */
    @Override
    public Integer update(MotorcycleType motorcycleType) {
        return motorcycleTypeMapper.updateByPrimaryKey(motorcycleType);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public Integer delete(Integer id) {
        return motorcycleTypeMapper.deleteByPrimaryKey(id);
    }
}
